# coding:utf-8

'''sqlite3学习'''

import sqlite3

# 如果文件不存在，会自动在当前目录创建:
conn=sqlite3.connect('test.db')
cursor=conn.cursor()

#创建表
# cursor.execute('create table user(id varchar(20) primary key,name varchar(20))')
#插入数据
# cursor.execute('insert into user (id,name) values (\'2\',\'tzj222\')')
# cursor.execute('insert into user (id,name) values (?,?)',('3','tanghzijie'))

# 通过rowcount获得插入的行数:
print cursor.rowcount

#查询
cursor.execute('select * from user where id =?',('3',))
# 获得查询结果集:
value=cursor.fetchall()
print value

# 关闭Cursor:
cursor.close()
# 提交事务:
conn.commit()
# 关闭Connection:
conn.close()


